package util.wcl
{
	import flash.external.ExternalInterface;
	import flash.net.URLVariables;

	public class ExternalCommand
	{
		public static function closeBrowser():void
		{
        	const FUNCTION_CLOSE_WINDOW:String = 
					"document.closeWindow = function () {" + 
					"if(navigator.appVersion.indexOf('MSIE 8.0')>=0) {" +
					"window.opener='Self';" +
					"window.open('','_parent','');" +
					"window.close();"+ 
					"}else if(navigator.appVersion.indexOf('MSIE 7.0')>=0) {" + 
						"window.open('about:blank','_self').close();" + 
					"}else {" + 
						"window.opener = self;" + 
						"self.close();" + 
					"}}";
			trace("onCloseBrowser");	
			ExternalInterface.call(FUNCTION_CLOSE_WINDOW);
			ExternalInterface.call("closeWindow");
 		}
 		
 		public static function popUpWindow(width:Number, height:Number, url:String):void
 		{
 			const FUNCTION_POPUP_WINDOW:String = 
 				"document.popUpWindow = function () {" +
 					"var t_width = " +width+";" +
 					"var t_height = " + height + ";" +
 					"var x = (screen.availWidth - t_width) / 2;" + 
 					"var y = (screen.availHeight - t_height) / 2;" + 
 					"window.open ('','DOCHTML','channelmode=no,location=no,status=no,width='+t_width+',height='+t_height+',left='+x+',top='+y+',scrollbars=yes,toolbars=no,resizable=yes');" + 
 					"document.form2.target = 'DOCHTML';" + 
 					"document.form2.action = '" + url + "';" + 
 					/*"document.form2.paramHtml.value = valhtml;" +*/ 
 					"if(navigator.appVersion.indexOf('MSIE 7.0')>=0) {" + 
 						"window.opener = self;" + 
 					"}" + 
 					"document.form2.submit();" + 
 				"}";
			ExternalInterface.call(FUNCTION_POPUP_WINDOW);
			ExternalInterface.call("popUpWindow");
 		}
 		
 		public function popupWindow(url:String, width:Number, height:Number, variables:URLVariables):void
 		{
			//ExternalInterface.call("function setWMWindow() {window.open('" + url + "');}"); 			
 		}
 		
 		public static function openURL(url:String):void
 		{
 			const FUNCTION_OPEN_WINDOW:String = 
 					"document.openURL = function() {" + 
 					"window.open('"+url+"', 'myOpen');" + 
 					"}";
			ExternalInterface.call(FUNCTION_OPEN_WINDOW);
			ExternalInterface.call("openURL");
 		}
	}
}